#!/bin/sh
#wang by 20161111
source /etc/profile
#back web data
ip=`awk '/IPADDR/' /etc/sysconfig/network-scripts/ifcfg-eth0 |awk -F "=" '{print $2}' `
mysql_bk_directory=/data/backup/mysql/${ip}
mysql_cnf_file='/etc/my.cnf'
shell_directory='/home/script'
mysql_password=''
#create directory for backup
[ ! -d ${mysql_bk_directory} ] && mkdir -p ${mysql_bk_directory}
#backup conf
cd /
tar zcf ${mysql_bk_directory}/etc_$(date +%Y%m%d).tar.gz ${mysql_cnf_file} >/dev/null 2>&1
tar zcf ${mysql_bk_directory}/server_scripts_$(date +%Y%m%d).tar.gz ${shell_directory} >/dev/null 2>&1
#backup mysql_data
mysqldump -uroot -p${mysql_password} --master-data=2 --ignore-table=mysql.event --lock-all-tables -B |gzip >${mysql_bk_directory}/mysql_$(date +%Y%m%d).sql.gz


#del
[ ! -d ${mysql_bk_directory} ] && mkdir -p ${mysql_bk_directory}
cd ${mysql_bk_directory}
find ${mysql_bk_directory} -name "*.gz"  -mtime +30 |xargs rm -f



















